"use strict";

const Service = require("egg").Service;

class UserService extends Service {
    //登录时的查询用户名和密码
    async cha(username, password) {
        let sql = "select * from user where username = ? and password=? ";
        let params = [username, password];
        let res = await this.app.mysql.query(sql, params);
        return res[0];
    }
    //注册接口
    async zhuce(username, password, nickname) {
        //contorller 传过来的数据
        let sql =
            "insert into user (username,password,nickname) values (?,?,?)"; //插入的sql
        //  let params = [username, password, nickname];
        //使用token中间件验证密码
        let params = [username, this.ctx.helper.enCrypto(password), nickname];
        let res = await this.app.mysql.query(sql, params);
        return res;
    }
    //查询接口
    async chaxun() {
        let sql = "select * from user";
        return await this.app.mysql.query(sql);
    }
}

module.exports = UserService;
